import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:ytbusiness/config/style.dart';
import 'package:ytbusiness/utils/screen_adaptation.dart';

//工时信息
class LaborHour extends StatefulWidget {
  @override
  _LaborHourState createState() => _LaborHourState();
}

class _LaborHourState extends State<LaborHour> {
  bool _laborHourShow = false;//配件显示隐藏
  List<String> _images = ["","",""];
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(top: setWidth(20),left: setWidth(15),right: setWidth(15),bottom: setWidth(20)),
      color: Colors.white,
      child: Column(
        children: [
          Container(
            margin: EdgeInsets.only(bottom: setWidth(5)),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Row(
                  children: [
                    Container(
                      width: setWidth(2.5),
                      height: setWidth(15),
                      color: Color(0xff00C65F),
                    ),
                    Container(
                      child: Text("工时信息"),
                      margin: EdgeInsets.only(left: setWidth(10)),
                    ),
                  ],
                ),
                GestureDetector(
                  behavior: HitTestBehavior.opaque,
                  onTap: (){
                    setState(() {
                      _laborHourShow = !_laborHourShow;
                    });
                  },
                  child: Container(//
                    padding: EdgeInsets.all(10),
                    child: SizedBox(
                      width: setWidth(12),
                      height: setWidth(6),
                      child: Image.asset(_laborHourShow?"assets/images/shouqi.png":"assets/images/zhankai.png",
                        width: setWidth(12),
                        height: setWidth(6), fit: BoxFit.cover,),
                    ),
                  ),
                ),

              ],
            ),
          ),
          Container(
            child: ListView.builder(
                physics: NeverScrollableScrollPhysics(),
                //默认显示一条
                itemCount: _laborHourShow ? (_images.length > 0
                    ? _images.length
                    : 0) : 1,
                shrinkWrap: true,
                itemBuilder: (context, index) {
                  return _laborHourItem();
                }),
          ),
          Container(
            margin: EdgeInsets.only(top: setWidth(15),bottom: setWidth(15)),
            height: setWidth(0.5),
            color: YTStyle.bgColor,

          ),
          Container(
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                _laborHourShow ?Container() : Container(
                  child:Text("已隐藏${_images.length - 1 }个工时",style: TextStyle(color: Color(0xff989898),fontSize: setSp(14)),),
                ),
                Container(
                  child:RichText(text: TextSpan(
                      children: [
                        TextSpan(text:"总计: ",style:TextStyle(color: Color(0xff010015),fontSize: setSp(15))),
                        TextSpan(text:"1432.64",style:TextStyle(color: Color(0xff323232),fontSize: setSp(15),fontWeight: FontWeight.w600)),
                        TextSpan(text:"元",style:TextStyle(color: Color(0xff010015),fontSize: setSp(15))),
                      ]
                  )),
                )
              ],
            ),
          )
        ],
      ),
    );
  }

  Widget _laborHourItem() {
    return Container(
      margin: EdgeInsets.only(top: setWidth(15),bottom: setWidth(15)),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            child: Text("漆面修复",style: TextStyle(color: Color(0xff010015),fontSize: setSp(15),fontWeight: FontWeight.w400),),
          ),
          SizedBox(
            height: setWidth(14),
          ),
          Container(
            child: Text("x1",style: TextStyle(color: Color(0xff999999),fontSize: setSp(12)),),
          ),
          SizedBox(
            height: setWidth(5),
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Container(
                child: Text("单价：300.00",style: TextStyle(color: Color(0xff999999),fontSize: setSp(12)),),
              ),
              Container(
                child: Text("￥520.00",style: TextStyle(color: Color(0xff010015),fontSize: setSp(16),fontWeight: FontWeight.w600),),
              ),
            ],
          )
        ],
      ),
    );
  }
}
